<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JsWs Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="module.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>module.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'module.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="Module.html">Module</a></b></td>
    <td>Represents a module loaded by JsWs
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is JsWs.
 *
 * The Initial Developer of the Original Code is
 * Chris Winberry.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */</span>

<span class="comment">/**
 * <span class="attrib">@class</span> Represents a module loaded by JsWs
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {String} id The module's ID (not extension ID)
 * <span class="attrib">@param</span> {nsIPrefBranch} prefBranch (optional) Preference branch to read module settings from
 * <span class="attrib">@exception</span> ExParamError
 */</span>
<span class="reserved">function</span> Module (id, prefBranch) {
	<span class="reserved">if</span> (prefBranch != null &amp;&amp; !(prefBranch instanceof Ci.nsIPrefBranch))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>prefBranch\<span class="literal">" is of an unexpected type ("</span> + typeof prefBranch + <span class="literal">")"</span>, 0, null, arguments));

	<span class="comment">/**
	 * Module identifier
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.id = id;
	<span class="comment">/**
	 * Path to the extension hosting the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.extensionPath = null;
	<span class="comment">/**
	 * Path, relative to {<span class="attrib">@link</span> #extensionPath} where the module's
	 * content is located
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.contentPath = null;
	<span class="comment">/**
	 * Path to where the module's document root should be
	 * <span class="attrib">@type</span> VirtualPath
	 */</span>
	<span class="reserved">this</span>.virtualPath = new VirtualPath(<span class="literal">"/"</span>);
	<span class="comment">/**
	 * Display name of the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.name = id;
	<span class="comment">/**
	 * Description of the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.description = <span class="literal">"Module: "</span> + <span class="reserved">this</span>.id;
	<span class="comment">/**
	 * Initialization page for the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.initPage = null;
	<span class="comment">/**
	 * Start/Home page for the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.startPage = null;
	<span class="comment">/**
	 * Custom page handler for requests in the module
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.handler = null;

	<span class="reserved">if</span> (prefBranch) {
		var children = prefBranch.getChildList(<span class="literal">""</span>, {});
		<span class="reserved">for</span> (var i = 0; i &lt; children.length; i++)
			<span class="reserved">this</span>.setProperty(children[i], prefBranch.getCharPref(children[i]));
	}
}

<span class="comment">/**
 * Set a module property. Maps preference name constants to
 *  actual properties to make loading from prefs easier.
 * <span class="attrib">@param</span> {String} name Name of the preference to set
 * <span class="attrib">@param</span> {String} value Value to set the property to
 */</span>
Module.<span class="reserved">prototype</span>.setProperty = <span class="reserved">function</span> (name, value) {
	switch (name) {
		case JSWS_MODULES_IDKEY :
			<span class="reserved">this</span>.id = value;
			var extManager = Cc[<span class="literal">"@mozilla.org/extensions/manager;1"</span>]
				.createInstance(Ci.nsIExtensionManager);
			<span class="reserved">this</span>.extensionPath = extManager
				.getInstallLocation(<span class="reserved">this</span>.id)
				.getItemLocation(<span class="reserved">this</span>.id)
				.path;
			break;
		case JSWS_MODULES_NAMEKEY :
			<span class="reserved">this</span>.name = value;
			break;
		case JSWS_MODULES_EXTENSIONPATHKEY :
			<span class="reserved">this</span>.extensionPath = value;
			break;
		case JSWS_MODULES_CONTENTPATHKEY :
			<span class="reserved">this</span>.contentPath = value;
			break;
		case JSWS_MODULES_VIRTUALPATHKEY :
			<span class="reserved">this</span>.virtualPath = value;
			break;
		case JSWS_MODULES_HANDLERKEY :
			<span class="reserved">this</span>.handler = value;
			break;
		case JSWS_MODULES_STARTPAGEKEY :
			<span class="reserved">this</span>.startPage = value;
			break;
		case JSWS_MODULES_DESCRIPTIONKEY :
			<span class="reserved">this</span>.description = value;
			break;
		case JSWS_MODULES_INITPAGEKEY :
			<span class="reserved">this</span>.initPage = value;
			break;
	}
}

<span class="comment">/**
 * Scans a preference branch for registered modules. Found modules
 *  are instanced and returned in an array.
 * <span class="attrib">@param</span> {String} prefBase Location in preferences to scan for modules
 * <span class="attrib">@returns</span> An array of found modules
 * $type {Module[]}
 */</span>
Module.loadFromPrefs = <span class="reserved">function</span> (prefBase) {
	var modules = new Array();
	try {
		var extManager = Cc[<span class="literal">"@mozilla.org/extensions/manager;1"</span>]
			.createInstance(Ci.nsIExtensionManager);
		var prefSvc = Cc[<span class="literal">"@mozilla.org/preferences-service;1"</span>]
			.getService(Ci.nsIPrefService);
		var prefBranch = prefSvc.getBranch(prefBase);
		var children = prefBranch.getChildList(<span class="literal">""</span>, {});
		<span class="reserved">for</span> (var i = 0; i &lt; children.length; i++) {
			var module = children[i].split(<span class="literal">'.'</span>)[0];
			<span class="reserved">if</span> (!modules[module])
				modules[module] = new Module(module, prefSvc.getBranch(prefBase + module + <span class="literal">"."</span>));
		}
	} catch (e) { }

	<span class="reserved">return</span>(modules);
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov  8 22:50:16 2007</div>
</body>
</html>
